#pragma once

#include <QAbstractTableModel>

class QTimeModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    explicit QTimeModel(int columnCount = 10, QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;

    int value() const;
    void setValue(int value);
    void setData(const QList<QString>& dataList);
    int minValue() const;
    void setMinValue(int min);
    int maxValue() const;
    void setMaxValue(int max);

    void cellForValue(int value, int *row, int *column) const;
    int valueForCell(int row, int column) const;
    QString displayText(const QModelIndex &index) const;
    void internalUpdate();

private:
    int valueNumber(const QString& data) const;

private:
    int _minValue{ 0 };
    int _maxVlaue{ 59 };
    int _curValue{ 0 };
    int _columnCount{ 10 };
    QList<QString> _dataList;
};
